package com.ledong.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ledong.servlet.entity.Emp;

public class ServletOne extends HttpServlet {

    private static final long serialVersionUID = -3212616198314038950L;

    public void doGet(HttpServletRequest request, HttpServletResponse response) {
        String str = (String) request.getSession().getAttribute("str");
        System.out.println(str);
        Emp emp = (Emp) request.getSession().getAttribute("emp");
        System.out.println(emp);

        System.out.println("这里是doGet");
        try {
            PrintWriter pw = response.getWriter();
            pw.print("Hello doGet");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) {

        System.out.println("这里是doPost");
        try {
            PrintWriter pw = response.getWriter();

            pw.print("<html>");
            pw.print("</body>");
            pw.print("Hello doPost");
            pw.print("<hr>");
            pw.print(request.getLocalAddr());
            pw.print("<hr>");
            pw.print(request.getRemoteHost());
            pw.print("<hr>");
            pw.print(request.getRemotePort());
            pw.print("<hr>");
            pw.print(request.getRemoteUser());
            pw.print("</body>");
            pw.print("</html>");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void init() {
        System.out.println("这里是init方法");
    }

    public void destory() {
        System.out.println("这里是destory方法");
    }
}
